package com.fusuhai.service.imp;

import com.fusuhai.bean.UserBean;
import com.fusuhai.dao.UserDao;
import com.fusuhai.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.List;

@Service
@Transactional
public class UserServiceImp implements UserService {

    @Resource
    private UserDao userDao;

    @Override
    public UserBean login(String userName, String userPwd) {
       return userDao.login(userName,userPwd);
    }

    @Override
    public void addUser(UserBean userBean) {
        userDao.addUser(userBean);
    }

    @Override
    public void deleteUser(int userId) {
        userDao.deleteUser(userId);
    }

    @Override
    public void updateUser(int userId, String newPwd) {
        userDao.updateUser(userId,newPwd);
    }

    @Override
    public PageInfo<UserBean> selectLevel(int pageNO, int pageSize, String userLevel) {
        PageHelper.startPage(pageNO, pageSize);
        PageInfo<UserBean> pageInfo=PageInfo.of(userDao.selectLevel(userLevel));
        return pageInfo;
    }

    @Override
    public void addDate(String userAccount, LocalDate date) {
        userDao.addDate("用户:"+userAccount+"登陆系统", date);
    }


    @Override
    public PageInfo<UserBean> selectDate(int pageNO, int pageSize, LocalDate sDate, LocalDate eDate) {
        PageHelper.startPage(pageNO, pageSize);
        PageInfo<UserBean> pageInfo=PageInfo.of(userDao.selectDate(sDate,eDate));
        return pageInfo;
    }

    @Override
    public PageInfo<UserBean> selectAllDate(int pageNO, int pageSize) {
        PageHelper.startPage(pageNO, pageSize);
        PageInfo<UserBean> pageInfo=PageInfo.of(userDao.selectAllDate());
        return pageInfo;
    }


}
